package com.mall.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitConfig {
    public static final String MALL_EXCHANGE="mall_topic_exchange";
    public static final String MALL_QUEUE="mall_queue";
    //声明交换机（名称，类型）
    @Bean("mallExchange")
    public Exchange mallExchange(){
        return ExchangeBuilder.topicExchange(MALL_EXCHANGE).durable(true).build();
    }
    //声明队列
    @Bean("mallQueue")
    public Queue mallQueue(){
        return QueueBuilder.durable(MALL_QUEUE).build();
    }
    //绑定交换机和队列和路由key
    @Bean
    public Binding bingQueueExchange(@Qualifier("mallExchange") TopicExchange exchange,@Qualifier("mallQueue") Queue queue){
        return BindingBuilder.bind(queue).to(exchange).with("mall.#");
    }
}
